package test04;

import java.util.Scanner;

/*
        用户名:必须是大小写字母,数字,_组合 3到16个字符
        密码:开头必须是大小写字母,或者数字,多个，后面加1个或者多个.  然后再加一个或者多个大小写字母,数字
        邮箱:：@前面可以是数字，字母，下划线。@后面是字母和.
              talta@sina.com.cn
 */
public class Test04 {
    public static void main(String[] args) {
        String username = "[A-Za-z0-9]{3,16}";
        String password = "[A-Za-z0-9]+\\.+[A-Za-z0-9]+";
        String email = "[A-Za-z0-9_]+@([a-z]+\\.[a-z]+)+";

        while(true){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请您输入用户名:");
            String name = scanner.next();
            System.out.println("请您输入密码:");
            String pwd = scanner.next();
            System.out.println("请您输入邮箱:");
            String em = scanner.next();

            boolean matches = name.matches(username);
            boolean matches1 = pwd.matches(password);
            boolean matches2 = em.matches(email);

            if (matches&&matches1&&matches2){
                System.out.println("注册成功!");
                break;
            }else{
                System.out.println("注册失败!");
            }
        }

    }
}
